package LeetCode.month02.day40;

import java.util.HashMap;
import java.util.Map;

public class No290 {
    public boolean wordPattern(String pattern, String s) {
        Map<Character,String> map = new HashMap<>();
        String[] strings = s.split(" ");
        if(strings.length!=pattern.length()) return false;
        for (int i = 0; i < pattern.length(); i++) {
            char c = pattern.charAt(i);
            if(map.containsKey(c)){
                if(!map.get(c).equals(strings[i])){
                    return false;
                }
            }else{
                if(map.containsValue(strings[i])){
                    return false;
                }
                map.put(c,strings[i]);
            }
        }
        return true;
    }
}
